// 全选
function checkBox(name,checked){
    //全选开始
    $("input[name='"+name+"']").prop("checked", checked);
}
// 删除
function deleteNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要删除选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type : "DELETE",
                    cache : false,
                    url : "/admin/processDefinition/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType:"json",
                    success: function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                            // 一秒后跳转
                            setTimeout("location.reload()", 1000);
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                            // 一秒后跳转
                            setTimeout("location.reload()", 1000);
                        }
                    },error : function(result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 启动
function startNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要启动选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type : "GET",
                    cache : false,
                    url : "/admin/processDefinition/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType:"json",
                    success: function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                            // 一秒后跳转
                            setTimeout("location.reload()", 1000);
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                        }
                    },error : function(result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 查看流程定义图片
function viewNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要查看选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type: "GET",
                    cache: false,
                    url: "/admin/processDefinition/view/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        $("#ImagePic").empty();
                        //将图片的Base64编码设置给src
                        $("#ImagePic").attr("src","data:image/png;base64,"+result);
                        $('#imgModal').modal({
                            keyboard : false,
                            show     : true
                        });
                    }, error: function (result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 节点处理人设置
function optSetNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要设置选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type: "GET",
                    cache: false,
                    url: "/admin/processDefinition/goAssignee/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        console.log(result.activityList);
                        $('#nodeModal').modal({
                            keyboard : false,
                            show     : true
                        });
                    }, error: function (result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 流程部署 zip、bar
function updateNode() {
    /*$("#uploader").empty();*/
    $('#updateFileModal').modal({
        keyboard : false,
        show     : true
    });
}
// 上传流程定义文件
$(function() {
    $('#uploaderExample').uploader({
        url : '/admin/processDefinition/fileUpload',
        chunk_size : 0,
        onUploadFile: function(file) {
            console.log('上传成功', file);
            new $.zui.Messager('提示消息：' + "上传模型成功", {
                icon: 'exclamation-sign',
                type: 'success',
                time: 2000
            }).show();
            // 一秒后跳转
            /*setTimeout("location.reload()", 1000);*/
        }
    });
});

